from django.db import models


# Create your models here.
# 建立图书表
class BookInfo(models.Model):
    name = models.CharField(max_length=11, unique=False, verbose_name="书名", null=True)
    id = models.CharField(max_length=10, unique=False, verbose_name="图书编号", primary_key=True)
    ISBN = models.CharField(max_length=10, unique=False, verbose_name="ISBN", null=True)
    type = models.CharField(max_length=10, unique=False, verbose_name="图书种类", null=True)
    author = models.CharField(max_length=10, unique=False, verbose_name="作者", null=True)
    type_num = models.CharField(max_length=10, unique=False, verbose_name="类型编号", null=True)
    pub_hou = models.CharField(max_length=20, unique=False, verbose_name="出版社", null=True)
    pub_date = models.DateTimeField(null=True, verbose_name="出版日期")
    edition = models.IntegerField(null=True, unique=False, verbose_name="版次")
    serial_num = models.CharField(max_length=10, unique=False, verbose_name="书架编号", null=True)
    state = models.BooleanField(default=False, verbose_name="图书状态")
    is_deleted = models.BooleanField(default=False, verbose_name='逻辑删除')

    class Meta:
        db_table = 'db_books'  # 自定义表名
        verbose_name = '图书'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.name


class BookType(models.Model):
    # 类型名称
    Type = models.CharField(max_length=10, unique=False, verbose_name="类型名称", null=True)
    # 类型编号
    Type_name = models.CharField(max_length=150, unique=False, verbose_name="类型编号", null=True)

    class Meta:
        db_table = 'db_BookType'
        verbose_name = '图书类型编号'
        verbose_name_plural = verbose_name

    def __init__(self, *args, **kwargs):
        super().__init__(args, kwargs)
        self.name = None

    def __str__(self):
        return self.name


class PubHouse(models.Model):
    # 出版社名称
    ISBN = models.CharField(max_length=10, unique=False, verbose_name="出版社ISBN", null=True)
    # 出版社编号
    CBSNC = models.CharField(max_length=10, unique=False, verbose_name="出版社名称", null=True)

    class Meta:
        db_table = 'db_PubHouse'
        verbose_name = '图书类型'
        verbose_name_plural = verbose_name

    def __init__(self, *args, **kwargs):
        super().__init__(args, kwargs)
        self.name = None

    def __str__(self):
        return self.name
